package cn.edu.neu.controller;

import cn.edu.neu.model.Category;
import cn.edu.neu.model.Goods;

import cn.edu.neu.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Controller
public class HomeController {
    @Autowired
    private HomeService homeService;

    @GetMapping(value = "/")
    public  String home(Model model){
        List<Goods> hotlist=homeService.getHotList();

        model.addAttribute("hotlist",hotlist);
        List<Category> cateList=homeService.getCateList();
        model.addAttribute("catelist",cateList);
        List<Goods> goodsList=new ArrayList<>();

        for (Category cate:cateList){
            List<Goods> list=homeService.getGoodsByCateID(cate.getCate_id());
            goodsList.addAll(list);
        }
        model.addAttribute("gooslist",goodsList);
//        System.out.println(cateList.size());
        return "client/home";
    }

}
